//
//  UILabel+Extension.swift
//  LiveTrivia
//
//  Created by 李响 on 2018/12/5.
//  Copyright © 2018 LiveTrivia. All rights reserved.
//

import UIKit

extension UILabel {
    
    var requiredWidth: CGFloat {
        let rect = CGRect(x: 0, y: 0, width: .greatestFiniteMagnitude, height: frame.height)
        let label = UILabel(frame: rect)
        label.numberOfLines = numberOfLines
        label.lineBreakMode = lineBreakMode
        label.font = font
        label.text = text
        label.attributedText = attributedText
        label.sizeToFit()
        return label.frame.width
    }
}
